use([
    "public/javascripts/service/order_manageinfoService.js",
    "public/javascripts/widget/slider/slider.js",
    "public/javascripts/order_manageinfo/view.js",
    "public/javascripts/widget/dialog/dialog.js",
    "public/javascripts/widget/prompt/prompt.js",
    "public/javascripts/widget/picPreview/picPreview.js"
], function (order_manageinfoService, SliderComponent, jQView, DialogComponent, PromptComponent, picPreview) {
    var PageComponent = React.createClass({
        componentDidMount: function () {
            easyMe.useJs(['common/uploadFile/uploadFile.js']);
            picPreview.init();
            var _this = this;
            jQView.init();
            _this.getProcess();
        },
        componentDidUpdate: function () {
            if (this.props.data.oid) {
                this.getUploadFiles(false, this.props.data.oid)
            }
        },
        getUploadFiles: function (flag, id) {
            var orderStatus = this.props.data.status;
            var param = {
                system: 'customer',
                edit: flag,
                btnHandle: true,
                orderStatus: orderStatus,
                append: '#listFileContent',
                orderNo: id,
                orderFileType: {
                    url: '/api/v1/order/attaches/fileTypes',
                    type: 'GET'
                },
                getOrderFile: {
                    url: '/api/v1/order/attaches',
                    type: 'GET',
                    param: {
                        pageIndex: 1,
                        pageSize: 50,
                        orderNo: id
                    }
                },
                delOrderFile: {
                    url: '',
                    type: 'POST',
                    param: {
                        orderNo: id,
                        orderFileId: ''
                    }
                },
                addOrderFile: {
                    url: '/api/v1/order/attaches/' + id + '/orderFiles',
                    type: 'POST',
                    param: {
                        orderNo: id,
                        orderFileId: ''
                    }
                },
                ckeckFileName: {
                    url: '/api/v1/order/attaches/name/check',
                    type: 'GET',
                    param: {
                        orderNo: id,
                        orderFileId: ''
                    }
                },
                prompt: PromptComponent,
                dialog: DialogComponent
            };
            $(document).uploadBox(param)
        },

        receiveMsg: function (data) {

        },
        getInitialState: function () {
            return this.props.data ? this.props.data : {};
        },
        render: function () {
            var data = this.state.data;
            var _this = this;

            var info = _this.state.info,
                status = (_this.state.status).toUpperCase(),
                list = _this.state.list ? _this.state.list : [],
                hasReceived = _this.state.hasReceived || false;
            console.log(info);


            if (info.ordSubOrderDtos && info.ordSubOrderDtos.length) {
                info.ordSubOrderDtos.forEach(function (item, index) {
                    if (item.length && item.width && item.height) {
                        item.lwhValue = item.length + '×' + item.width + '×' + item.height;
                    } else {
                        item.lwhValue = '';
                    }
                });
            }

            var orderStatusCode = 1;
            switch (status) {
                case 'RECEIVED':
                    orderStatusCode = 7;
                    break;    //已签收
                case 'DISPACTCHING':
                    orderStatusCode = 6;
                    break;    //配送中
                case 'TRANSPORT':
                    orderStatusCode = 5;
                    break;    //运输中
                case 'RECEGOOD':
                    orderStatusCode = 4;
                    break;    //已收货
                case 'ACCEPT':
                    orderStatusCode = 3;
                    break;    //已受理
                case 'COMMITED':
                    orderStatusCode = 2;
                    break;    //已提交
                default:
                    orderStatusCode = 1;    //草稿
            }

            return ~init;
        },
        getProcess: function () {
            var _this = this;
            order_manageinfoService.getProcess({'urlParams': [_this.state.info.waybillNo]}, function (res) {
                if (res.errorCode === 0) {
                    var data = _this.reData(res.data[_this.state.info.waybillNo]);

                    _this.setState({list: data});
                }
            });
        },
        reData: function (data) {
            var _this = this;

            var ret = [];
            for (var i in data) {
                var map = {
                    subNum: i,
                    subInfo: data[i]
                };
                ret.push(map);
            }
            return ret;
        }
    });
    if (typeof ReactDOM != "undefined") {
        ReactDOM.render(<PageComponent data={storage}/>, document.getElementById('container'));
    }
    module.exports = PageComponent;
});
